package com.chang.cheng.toutiaoserver.model.user.pojos;

import lombok.Data;
import org.apache.ibatis.annotations.Result;

import java.util.Random;

/**
 * @Auther: asus
 * @Date: 2022/01/07 11:24
 * @Description:
 */
@Data
public class Article {
    private String title;
    private Long id;
    private Long author_id;
    private Long channel_id;
    private Long comm_count;
    private String images;
    private String aut_name;
    private String pubdate;
    private Cover cover;

    public void setImages(String images) {
        this.images = images;
        // 中国人口总数,comm_count没有,用随机数代替
        this.comm_count = (long) new Random().nextInt(141178 * 10000);
        Long type=0L;
        String[] imgs=new String[0];
        // 去掉所有空格,以免后面出错.
        String images1=images.replace(" ","");
        // 图片列表
        String[] pics={"https://s2.loli.net/2022/01/09/XCS4AjDJNqyoPEz.jpg","https://s2.loli.net/2022/01/09/etKwi9gBR7HWCpA.png","https://s2.loli.net/2022/01/09/PWMifwuymTXChsU.png","https://s2.loli.net/2022/01/09/IslWyXdkVbqN6fL.png","https://s2.loli.net/2022/01/09/rDBZ5EnNoXQJdxU.png","https://s2.loli.net/2022/01/09/1wDQvtyuOjmqxGL.png","https://s2.loli.net/2022/01/09/1kH47SscT8OvPJa.png","https://s2.loli.net/2022/01/09/n7F1HUBZ2cKew46.png"
        };
        int count=  pics.length;
        if(images1.equals("[]") || images1.equals("")){
            type=0L;
            imgs=new String[0];
        }else{
            // 去掉[]后的图片字符串
            String replace = images1.replace("[", "").replace("]", "");
            // 将这些不识别的图片替换掉
            String replace1 = replace.replace("https://ss.csdn.net/p", pics[new Random().nextInt(count)]);
            imgs = replace1.split(",");
            type = (long) imgs.length;
        }
        Cover cover1=new Cover();
        cover1.setImages(imgs);
        cover1.setType(type);
        this.cover=cover1;
    }
}
